﻿using System;
using UnityEngine;

// Token: 0x020002E5 RID: 741
public class AudioControl : MonoBehaviour
{
	// Token: 0x170001BB RID: 443
	// (get) Token: 0x060012BD RID: 4797 RVA: 0x00087574 File Offset: 0x00085774
	// (set) Token: 0x060012BE RID: 4798 RVA: 0x0008757C File Offset: 0x0008577C
	public string BGM_Name { get; private set; }

	// Token: 0x170001BC RID: 444
	// (get) Token: 0x060012BF RID: 4799 RVA: 0x00087588 File Offset: 0x00085788
	public bool PlayingBGM
	{
		get
		{
			return this.bgmCtrl.IsPlaying;
		}
	}

	// Token: 0x060012C0 RID: 4800 RVA: 0x00087598 File Offset: 0x00085798
	private void Awake()
	{
		this.bgmSource.loop = true;
		this.bgmCtrl = new BGM_Control(this.bgmSource);
		this.bgmABC = new AssetBundleController();
		this.bgmABC.OpenFromFile(GlobalData.assetBundlePath, "bgm");
	}

	// Token: 0x060012C1 RID: 4801 RVA: 0x000875D8 File Offset: 0x000857D8
	private void OnDestroy()
	{
		this.bgmABC.Close(false);
	}

	// Token: 0x060012C2 RID: 4802 RVA: 0x000875E8 File Offset: 0x000857E8
	private void Update()
	{
		this.UpdateBGM(Time.deltaTime);
		this.Update2DSE();
	}

	// Token: 0x060012C3 RID: 4803 RVA: 0x000875FC File Offset: 0x000857FC
	private void UpdateBGM(float updateTime = 0f)
	{
		this.bgmCtrl.Update();
	}

	// Token: 0x060012C4 RID: 4804 RVA: 0x0008760C File Offset: 0x0008580C
	private void Update2DSE()
	{
		if (this.reserve2DClip != null)
		{
			SoundEffect soundEffect = UnityEngine.Object.Instantiate<SoundEffect>(this.se2D);
			soundEffect.type = SoundEffect.TYPE.TYPE_SYSTEM;
			soundEffect.Play(this.reserve2DClip);
			soundEffect.transform.SetParent(base.transform);
			this.reserve2DClip = null;
		}
	}

	// Token: 0x060012C5 RID: 4805 RVA: 0x00087664 File Offset: 0x00085864
	public void BGM_Load(string file)
	{
		if (this.BGM_Name == file)
		{
			return;
		}
		AudioClip audioClip = this.bgmABC.LoadAsset<AudioClip>(file);
		if (audioClip == null)
		{
			GlobalData.Debug_LogError("看不懂背景音乐:" + file);
			return;
		}
		this.BGM_Name = file;
		this.BGM_Load(audioClip);
	}

	// Token: 0x060012C6 RID: 4806 RVA: 0x000876BC File Offset: 0x000858BC
	private void BGM_Load(AudioClip clip)
	{
		this.bgmCtrl.ChangeClip(clip, this.bgmFadeSpeed);
	}

	// Token: 0x060012C7 RID: 4807 RVA: 0x000876D0 File Offset: 0x000858D0
	private void BGM_LoadAndPlay(string file)
	{
		this.BGM_Name = file;
		AudioClip clip = this.bgmABC.LoadAsset<AudioClip>(file);
		if (this.bgmCtrl.IsPlaying)
		{
			this.bgmCtrl.ChangeClip(clip, this.bgmFadeSpeed);
		}
		else
		{
			this.bgmCtrl.ChangeClip(clip, 0f);
			this.bgmCtrl.Play(0f);
		}
	}

	// Token: 0x060012C8 RID: 4808 RVA: 0x0008773C File Offset: 0x0008593C
	public void BGM_LoadAndPlay(string file, bool sameRestart = false, bool forcePlay = false)
	{
		if (this.bgmSource.isPlaying && this.BGM_Name == file && !sameRestart)
		{
			return;
		}
		this.BGM_Name = file;
		this.BGM_LoadAndPlay(file);
	}

	// Token: 0x060012C9 RID: 4809 RVA: 0x00087774 File Offset: 0x00085974
	public void BGM_Play()
	{
		this.bgmCtrl.Play(0f);
	}

	// Token: 0x060012CA RID: 4810 RVA: 0x00087788 File Offset: 0x00085988
	public void BGM_Stop()
	{
		this.bgmCtrl.Stop(this.bgmFadeSpeed);
	}

	// Token: 0x060012CB RID: 4811 RVA: 0x0008779C File Offset: 0x0008599C
	public void Play2DSE(AudioClip clip)
	{
		this.reserve2DClip = clip;
	}

	// Token: 0x060012CC RID: 4812 RVA: 0x000877A8 File Offset: 0x000859A8
	public void Play3DSE(AudioClip clip, Vector3 pos)
	{
		SoundEffect soundEffect = UnityEngine.Object.Instantiate<SoundEffect>(this.se3D);
		soundEffect.Play(clip);
		soundEffect.transform.SetParent(base.transform);
		soundEffect.transform.position = pos;
	}

	// Token: 0x040017B4 RID: 6068
	[SerializeField]
	private AudioSource bgmSource;

	// Token: 0x040017B5 RID: 6069
	[SerializeField]
	private string bgmAssetBundle = "bgm";

	// Token: 0x040017B6 RID: 6070
	[SerializeField]
	private float bgmFadeSpeed = 2f;

	// Token: 0x040017B7 RID: 6071
	private BGM_Control bgmCtrl;

	// Token: 0x040017B9 RID: 6073
	private AssetBundleController bgmABC;

	// Token: 0x040017BA RID: 6074
	[SerializeField]
	private SoundEffect se2D;

	// Token: 0x040017BB RID: 6075
	[SerializeField]
	private SoundEffect se3D;

	// Token: 0x040017BC RID: 6076
	public AudioClip systemSE_yes;

	// Token: 0x040017BD RID: 6077
	public AudioClip systemSE_no;

	// Token: 0x040017BE RID: 6078
	public AudioClip systemSE_choice;

	// Token: 0x040017BF RID: 6079
	public AudioClip systemSE_open;

	// Token: 0x040017C0 RID: 6080
	public AudioClip systemSE_close;

	// Token: 0x040017C1 RID: 6081
	private AudioClip reserve2DClip;
}
